package com.automannn.seataSamples.api.aop;

import com.automannn.seataSamples.api.response.ObjectResponse;
import com.automannn.seataSamples.api.response.ResponseStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author automannn
 * @Date 2022/3/24
 * @Description 全局异常处理器
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ObjectResponse exceptionHandler(Exception e){
        log.error("【系统抛出异常】----异常内容:{}",e);
        ObjectResponse objectResponse = new ObjectResponse();
        objectResponse.setStatus(ResponseStatusEnum.FAIL.getCode());
        objectResponse.setMessage(ResponseStatusEnum.FAIL.getMessage());
        return objectResponse;
    }
}
